<template>
	<view class="wrapper">
		<head-title titleText="获取心动花朵" showLeftButton="true"></head-title>
		<image class="logo" src="../../static/image/maxhua.png" mode="aspectFill"></image>
		<view class="logoTxt">你有 <text>{{nums}}</text> 朵花</view>
		<view class="title">
			= <text>获取花朵的办法</text> =
		</view>
		<view class="list">
			每天进入该小程序，系统赠送3朵
		</view>
		<view class="list">
			发布社区动态，得到别人打赏的花朵
		</view>
		<!-- <view class="list">
			分享给朋友，系统赠送5朵，每天限一次
		</view> -->
		<view class="list">
			分享到微信群，系统赠送10朵，每天限一次
		</view>
		<view class="otherTxt">【以上方式所得花朵都是累加的】</view>
		
		<view class="title">
			= <text>花朵有什么用处</text> =
		</view>
		<view class="list">
			用来解锁你感兴趣的用户信息主页。
		</view>
		<view class="list">
			打赏社区圈的朋友，给予别人支持，
		</view>
		<view class="list">
			吸引别人的注意。
		</view>
		<view class="btnCont flex_row">
			<button open-type="share" class="btnActive share getBtn">分享获取</button>
			<button @tap="bindBuy" class="btnActive getBtn">购买花朵</button>
		</view>
	</view>
</template>

<script>
	import common from "../../common/network.js";
	import headTitle from "../../components/headTitle.vue";
	var session = '';
	export default {
		components:{headTitle},
		data(){
			return{
				nums:'',sharemsg:'',rmb:'',buyhua:''
			}
		},
		onLoad:function(options){
			var that = this;
			console.log(options)
			if(options.session!=undefined){
				session = options.session;
				that.hua();
			}
		},
		onShow:function(){
			uni.showShareMenu({
				withShareTicket: true,
			})
		},
		onShareAppMessage:function(){
			var sharemsg = this.sharemsg;
			var that = this;
			that.shareData(2);
			return{
				title:sharemsg.c_title,
				path:'/pages/index/index',
				imageUrl: sharemsg.c_img,
// 				success:function(e){
// 					console.log(e);
// 					if(e.shareTickets){
// 						console.log('分享到了群');
// 						that.shareData(2);
// 					}else{
// 						console.log('分享到了好友');
// 						that.shareData(1);
// 					}
// 				},
// 				complete:function(err){
// 					console.log('完成')
// 					console.log(err)
// 				}
			}
		},
		methods:{
			getshareImg:function(){
				var that = this;
				var $data = {
					'type':'zshare_share_qian',
					'session':session,
					'c_type':0,
				};
				common.network.request($data,function(res){
					console.log(res)
					that.sharemsg = res;
				})
			},
			shareData:function(qun){
				var that = this;
				var $data = {
					'type':'zshare_share_flower',
					'session':session,
					'is_qun':qun
				};
				common.network.request($data,function(res){
					console.log(res);
					that.hua();
				})
			},
			hua:function(){
				var that = this;
				var $data = {
					'type':'zshare_get_flower',
					'session':session
				};
				common.network.request($data,function(res){
					console.log(res);
					that.rmb=res.buy_flower_money;
					that.buyhua = res.buy_flower_num;
					that.nums = res.flower_num;
					that.getshareImg();
				})
			},
			bindBuy:function(){
				var that = this;
				var rmb = this.rmb;
				var buyhua = this.buyhua;
				uni.showModal({
					content: '花费'+rmb+'元钱购买'+buyhua+'朵花',
					confirmColor: '#6673FF',
					confirmText: '立即购买',
					success:function(res){
						if(res.confirm){
							that.buyHua();
						}
					}
				})
			},
			buyHua:function(){
				var that = this;
				var $data = {
					'type':'zpay_flower_pay',
					'session':session,
				};
				common.network.request($data,function(res){
					uni.requestPayment({
						"timeStamp": (res.timeStamp).toString(),
						"nonceStr": res.nonceStr,
						"signType":"MD5",
						"package": res.package,
						"paySign": res.paySign,
						success:function(res){
							uni.showToast({
								icon:"success",
								title:'购买成功',
								success:function(){
									that.hua();
								}
							})
						}
					})
				})
			},
		}
	}
</script>

<style scoped>
	.wrapper{
		text-align: center;
	}
	.logo{
		width: 110px;
		height: 110px;
		margin-top: 100px;
	}
	.logoTxt{
		font-size: 26px;
		padding: 14px 0;
		padding-bottom: 0;
	}
	.logoTxt text{
		color: #D221F4;
	}
	.title{
		margin-top: 60px;
		padding-bottom: 14px;
	}
	.title text{
		font-weight: bold;
		font-size: 32px;
	}
	.list{
		line-height: 54px;
		font-size: 28px;
	}
	.otherTxt{
		font-size: 24px;
		color: #6278FF;
	}
	.btnCont{
		padding: 30px;
		padding-top: 60px;
	}
	.btnCont button{
		width: 44%;
		line-height: 80px;
		border-radius: 0;
		font-size: 32px;
		color: #fff;
		border-radius: 80px;
	}
	.getBtn{
		background: #6673FF;
		border: 1px solid #6673FF;
	}
	.getBtn.share{
		background: #fff;
		color: #6673FF;
		border: 1px solid #6673FF;
	}
</style>
